package outputAdapters;

import inputs.Input;
import dataModifiers.Modifier;
import management.UpdateManager;

/**
 * Singleton factory class for creating OutputAdapters.
 * Creating OutputAdapters through this class ensures they are added to the UpdateManager.
 * 
 * @author Dylan James
 *
 */
public class OutputAdapterFactory {
	private static OutputAdapterFactory instance;
	
	private UpdateManager updateManager;
	
	/**
	 * @return An instances of the OutputAdapter Factory
	 */
	public static OutputAdapterFactory getFactory()
	{
		if (instance == null)
		{
			instance = new OutputAdapterFactory();
		}
		
		return instance;
	}
	
	private OutputAdapterFactory()
	{
		updateManager = UpdateManager.getUpdateManager();
	}
	
	/**
	 * Adds an OutputAdapter to the update management
	 * @param input OutputAdapter to add
	 * @param update True if this OutputAdapter should be automatically updated each tick.
	 */
	private void Add(OutputAdapter adapter, boolean update)
	{
		updateManager.Add(adapter, update);
	}
	
	/**
	 * Creates a ScaleAdapter and adds it to the UpdateManagement.
	 * @param outputRange The Range of output for the Scale Adapter.
	 * @param input The input to modify.
	 * @param update Whether this ScaleAdapter should be automatically updated each tick.
	 * @return The created ScaleAdapter.
	 */
	public ScaleAdapter createScaleAdapter(Range outputRange, Input input, boolean update)
	{
		ScaleAdapter scaleAdapter = new ScaleAdapter(outputRange, input);
		Add(scaleAdapter, update);
		return scaleAdapter;
	}
	
	/**
	 * Creates a ScaleAdapter and adds it to the UpdateManagement.
	 * Automatically updates it each tick.
	 * @param outputRange The Range of output for the Scale Adapter.
	 * @param input The input to modify.
	 * @return The created ScaleAdapter.
	 */
	public ScaleAdapter createScaleAdapter(Range outputRange, Input input)
	{
		return createScaleAdapter(outputRange, input, true);
	}
	
	
}
